package root.electronclass.electronclass.mvp.model;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.MutableLiveData;

import root.electronclass.electronclass.mvp.base.BaseResponse;
import root.electronclass.electronclass.mvp.base.CallbackNext;
import root.electronclass.electronclass.mvp.base.DialogViewModel;
import root.electronclass.electronclass.mvp.rest.RestManager;

import retrofit2.Call;


/**
 * 用户登录、注册、获取验证码、注销
 */
public class UserViewModel extends AndroidViewModel {
    private DialogViewModel mDialogViewModel;

    private MutableLiveData<BaseResponse<String>> mDeviceLogin;

    public UserViewModel(@NonNull Application application, DialogViewModel dialogViewModel) {
        super(application);
        this.mDialogViewModel = dialogViewModel;

        mDeviceLogin = new MutableLiveData<BaseResponse<String>>();

    }

    public MutableLiveData<BaseResponse<String>> getmLogin() {
        return mDeviceLogin;
    }

    /**
     * 登录
     */
    public void deviceLogin(String code) {
        RestManager.getInstance().initRest().deviceLogin(code).enqueue(new CallbackNext<BaseResponse<String>>(mDialogViewModel) {
            @Override
            public void onSuccessful(Call<BaseResponse<String>> call, BaseResponse<String> response) {
                mDeviceLogin.setValue(response);
            }

            @Override
            public void onError(Call<BaseResponse<String>> call, BaseResponse<String> response) {

            }
        });
    }


}
